import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: null
  },
  getters: {
  },
  mutations: {
    setToken(state, token) {
      this.state.token = token
    }
  },
  actions: {
    loginAsync(context,formData) {
      console.log(formData);
      // 请求api
      axios.post('http://47.121.191.229/api/log', formData)
        .then(function (response) {
          console.log(response);
          if (response.status == 200 && response.data.code == '00000') {
            context.commit('setToken', response.data.token)
          }
        })
        .catch(function (error) {
          console.log(error);
        });
    }
  },
  modules: {
  }
})
